package com.wqr.controller;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wqr.pojo.UserStates;
import com.wqr.service.UserStatesService;

@Controller
public class UserStatesController {
	@Autowired
    public UserStatesService userStatesService;
	
	@RequestMapping("/addUserStates")
	@ResponseBody// 返回的数据不是html标签的页面，而是其他某种格式的数据时（如json、xml等）使用；
	public int addUserStates(@RequestBody //读取Request请求的body部分数据,再把HttpMessageConverter返回的对象数据绑定到 controller中方法的参数上
			UserStates userStates) throws Exception {
		//IsLogin(session);
		int a = userStatesService.insertUserStates(userStates);
		return a;
		//return "redirect:/manageUserStates.action";
	}
	//@RequestMapping(value="/deleteUserStates/{userStateId}",method=RequestMethod.GET)
	@RequestMapping("/deleteUserStates")
	@ResponseBody// 返回的数据不是html标签的页面，而是其他某种格式的数据时（如json、xml等）使用；
	public int deleteUserStates(@RequestBody //读取Request请求的body部分数据,再把HttpMessageConverter返回的对象数据绑定到 controller中方法的参数上
			UserStates userStates) throws Exception {
		//@pathVariable //将 URL 中占位符参数绑定到控制器处理方法的入参中 URL 中的 {xxx} 占位符可以通过@PathVariable("xxx") 绑定到操作方法的入参中。
		//(userStateId) Integer userStateId) throws Exception {
		//IsLogin(session);
		int a = userStatesService.delectUserStates(userStates.getUserStateId());
		return a;
	}
	@RequestMapping("/updateUserStates")
	@ResponseBody
	public List<UserStates> updateUserStates(@RequestBody UserStates userStates) throws Exception {
		//IsLogin(session);
		List<UserStates> itemList = userStatesService.selectByWhere(userStates);
		return itemList;
	}
	@RequestMapping("/saveUserStates")
	@ResponseBody// 返回的数据不是html标签的页面，而是其他某种格式的数据时（如json、xml等）使用；
	public int saveUserStates(@RequestBody UserStates userStates) throws Exception {
		//IsLogin(session);
		int a = userStatesService.updateUserStates(userStates);
		return a;
	}
	//LoginstateBean loginState = service.getLoginstateByLoginStateId(loginStateId);
	@RequestMapping("/searchUserStates")
	@ResponseBody
	public List<UserStates> searchUserStates(@RequestBody UserStates userStates,Model model) throws Exception {
		if(userStates.getUserStateName() == ""){
			userStates.setUserStateName(null);
		}
		if(userStates.getDescription() == ""){
			userStates.setDescription(null);
		}
		List<UserStates> itemList = userStatesService.selectUserStates(userStates);
	    return itemList;
	}
	@RequestMapping("/searchAllUserStates")
	@ResponseBody
	public List<UserStates> searchAllUserStates() throws Exception {
		List<UserStates> itemList = userStatesService.selectAll();
	    return itemList;
	}
	@RequestMapping("/manageUserStates")
	public String userStates(Model model) throws Exception {
		List<UserStates> list = userStatesService.list();
		model.addAttribute("itemList", list);
	    return "manageLoginStates"; 
	}
}
